//
//  HmLowLightButton.m
//  SmartHomeViews
//
//  Created by haimen_ios_imac on 2017/4/26.
//  Copyright © 2017年 深圳海曼科技有限公司. All rights reserved.
//

#import "HmLowLightButton.h"

@implementation HmLowLightButton


+ (instancetype)lowLightButtonWithTitle:(NSString *)title
                                  image:(NSString *)nImage
                            selectImage:(NSString *)sImage
                               tinColor:(UIColor *)nColor
                         selectTinColor:(UIColor*)sColor
                              titleFont:(CGFloat)font
{
    HmLowLightButton *btn = [HmLowLightButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:UIImageImage(nImage) forState:UIControlStateNormal];
    [btn setImage:UIImageImage(sImage) forState:UIControlStateSelected];
    [btn setTitleColor:nColor forState:UIControlStateNormal];
    [btn setTitleColor:sColor forState:UIControlStateSelected];
    btn.titleLabel.font = [UIFont systemFontOfSize:font];
    return btn;
}

- (void)setHighlighted:(BOOL)highlighted
{
    
}

-(id)initWithCoder:(NSCoder *)aDecoder{
    if (self=[super initWithCoder:aDecoder]) {
        [self commonInit];
    }
    return self;
}

-(id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    
    //self.titleLabel.font = [UIFont systemFontOfSize:14];
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleX = 0;
    CGFloat ww = CGRectGetWidth(contentRect);
    CGFloat hh = CGRectGetHeight(contentRect);
    CGFloat titleW = ww;
    CGFloat titleH = hh*.4;
    CGFloat titleY = hh-titleH;
    return CGRectMake(titleX, titleY, titleW, titleH);
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat height = CGRectGetHeight(contentRect);
    CGFloat imageW = CGRectGetWidth(contentRect);
    CGFloat imageH = height * 0.6;
    return CGRectMake(0, .0f, imageW, imageH);
}

@end
